package com.caine.sbs;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

/**
 * 1.能以jar方式启动是因为插件spring-boot-maven-plugin
 * 打包后的中包含Main-Class  Start-Class Spring-Boot-Lib  Spring-Boot-Classes 等信息
 * 启动的实际是org.springframework.boot.loader.launch方法
 *  该方法自定义类加载器然后加载lib  然后再启动一个子线程启动Start-Class
 *
 */

/**
 * 2.内置web容器
 *  org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration
 *
 */

/**
 * 3.外置容器
 *  首先需要剔除内置的tomcat
 *     <exclusions>
 *                 <exclusion>
 *                     <groupId>org.springframework.boot</groupId>
 *                     <artifactId>spring-boot-starter-tomcat</artifactId>
 *                 </exclusion>
 *    </exclusions>
 *   其次启动类需要extends SpringBootServletInitializer
 */
@SpringBootApplication
public class SBSApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
//        SpringApplication.run(WebApplication.class, args);
        SpringApplication boot = new SpringApplication(SBSApplication.class);
        boot.setWebApplicationType(WebApplicationType.SERVLET);
        boot.run(args);
    }
    @Override
    public SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(SBSApplication.class);
    }

}
